#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;
const int N = 1e5 + 10;

//  x    (a * x + b) * c = a * c * x + b * c
//         (ac * x + bc + d) * e  ---> acex + (bc + d)e

int n, m, p;
LL q[N];
struct Node
{
    int l, r;
    LL add, mul, sum;
}node[N * 4];

void pushup(int u){
    node[u].sum = (node[u << 1].sum + node[u << 1 | 1].sum) % p; 
}


void eval(Node& node, LL add, LL mul){
    node.sum = (node.sum * mul % p + (node.r - node.l + 1) * add % p) % p;
    node.mul = node.mul * mul % p;
    node.add = (node.add * mul + add) % p;
}

void pushdown(int u){
    LL add = node[u].add, mul = node[u].mul;
    eval(node[u << 1], add, mul);
    eval(node[u << 1 | 1], add, mul);
    node[u].add = 0, node[u].mul = 1;
}

void build(int u, int l, int r){
    node[u].l = l, node[u].r = r, node[u].add = 0, node[u].mul = 1;
    if(l == r){
        node[u].sum  = q[l] % p;
        return;
    }
    node[u].sum = 0;
    int mid = l + r >> 1;
    build(u << 1, l, mid), build(u << 1 | 1, mid + 1, r);
    pushup(u);
}


void modify(int u, int l, int r, LL add, LL mul){
    if(node[u].l >= l && node[u].r <= r){
        eval(node[u], add, mul);
    }else{
        pushdown(u);
        int mid = node[u].l + node[u].r >> 1;
        if(l <= mid) modify(u << 1, l, r, add, mul);
        if(r > mid) modify(u << 1 | 1, l, r, add, mul);
        pushup(u);
    }
}


LL query(int u, int l, int r){
    if(node[u].l >= l && node[u].r <= r){
        return node[u].sum % p;
    }else{
        pushdown(u);
        LL res = 0;
        int mid = (node[u].l + node[u].r) >> 1;
        if(l <= mid) res = (res + query(u << 1, l, r)) % p;
        if(r > mid) res = (res + query(u << 1 | 1, l, r)) % p;
        return res;
    }
}

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    
    scanf("%d%d%d", &n, &m, &p);

    for(int i = 1; i <= n; i ++) scanf("%lld", &q[i]);
    build(1, 1, n);

    int op, l, r;
    LL k;
    while(m --){
        scanf("%d%d%d", &op, &l, &r);

        if(op == 1){
            scanf("%lld", &k);
            modify(1, l, r, 0, k);
        }else if(op == 2){
            scanf("%lld", &k);
            modify(1, l, r, k, 1);
        }else{
            LL res = query(1, l, r) % p;
            printf("%lld\n", res); 
        }
    }
    return 0;
}